﻿using System.Collections.Generic;

namespace ObjetoNegocio
{
    public class Algoritmo : IObject
    {

        public List<Atributo> Atributos{ get; set;}
        public decimal Codigo { get; set; }
        public string Nome { get; set; }
        public string Descricao { get; set; }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Algoritmo)) return false;
            return Equals((Algoritmo) obj);
        }

        public bool Equals(Algoritmo obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            var temp =  obj.Codigo == Codigo && Equals(obj.Nome, Nome) && Equals(obj.Descricao, Descricao);
            
            if (Atributos != null && obj.Atributos != null && Atributos.Count == obj.Atributos.Count)
            {
                for (int i = 0; i < Atributos.Count; i++)
                {
                    temp = Atributos.Contains(obj.Atributos[i]) && temp;
                }
            }
            else
            {
                temp = false;
            }

            return temp;
            return temp;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = Codigo.GetHashCode();
                return result;
            }
        }
    }
}
